<?php

namespace falcon5\inc\WPProviders;

use falcon5\inc\Base\ServiceProviderInterface;
use falcon5\inc\Pages\PageSlugConstants;

/**
 * Class AdminRedirect
 * @package falcon5\inc\WPProviders
 * @desc Handles admin redirects after plugin activation
 */
class AdminRedirect implements ServiceProviderInterface
{

    public function register()
    {
        add_action('admin_init', [$this, 'redirectAfterActivation']);
    }

    /**
     * Redirect to plugin settings page after activation
     */
    public function redirectAfterActivation()
    {
        // Check if our transient exists
        if (get_transient('falcon5_activation_redirect')) {
            // Delete the transient
            delete_transient('falcon5_activation_redirect');

            // Make sure it's not a network activation and we're on the main dashboard
            if (!is_network_admin() && !isset($_GET['activate-multi'])) {
                // Redirect to the settings page
                wp_safe_redirect(admin_url('admin.php?page=' . PageSlugConstants::SETTINGS_SLUG));
                exit;
            }
        }
    }
}